package com.marketingexpert.controller.personmgnt;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.config.Configuration;
import com.marketingexpert.domain.User;
import com.marketingexpert.service.snsmgnt.SnsService;
import com.marketingexpert.service.snsmgnt.SnsServiceFactory;
import com.marketingexpert.service.usermgnt.UserService;
import com.marketingexpert.util.WebUtils;

public class AutoFollowUsController implements Controller {
	
	private UserService userService;
	
	private SnsServiceFactory snsServiceFactory;
	
	private Configuration configuration;
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse arg1) throws Exception {
		String userId = request.getParameter("userId");
		
		User user = getUserService().queryUserByUId(userId);
		SnsService snsService = WebUtils.getSnsService(user, getSnsServiceFactory());
		String officatialId = configuration.getOfficialWeibo(user.getUserType());
		snsService.createFriendship(user.getAccessToken(), user.getSecret(), officatialId);
		return null;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public SnsServiceFactory getSnsServiceFactory() {
		return snsServiceFactory;
	}

	public void setSnsServiceFactory(SnsServiceFactory snsServiceFactory) {
		this.snsServiceFactory = snsServiceFactory;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
}

